Page({
  data: {
    title: '',
    description: '',
  },
  onTitleInput: function(e) {
    this.setData({ title: e.detail.value });
  },
  onDescriptionInput: function(e) {
    this.setData({ description: e.detail.value });
  },
  saveTodo: function() {
    if (!this.data.title.trim()) {
      wx.showToast({
        title: '标题不能为空',
        icon: 'none'
      });
      return;
    }
    const todos = wx.getStorageSync('dataList') || [];
    const newTodo = {
      id: Date.now().toString(),
      title: this.data.title,
      completed: false,
      description: this.data.description
    };
    todos.push(newTodo);
    wx.setStorageSync('dataList', todos);
    wx.navigateBack();
  }
});